package com.ea.admin.controller.tutelage;


import com.ea.admin.pojo.param.report.GetStatsReportParam;
import com.ea.admin.service.StatsService;
import com.ea.admin.utils.NowUserGetter;
import com.ea.common.auth.NowUser;
import com.ea.common.log.LogAnnotation;
import com.ea.common.report.pojo.vo.StatsReportVo;
import com.ea.common.result.BizException;
import com.ea.common.result.ErrorCode;
import com.ea.common.result.Result;
import com.ea.common.utils.ParamUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@Api(tags = "监护管理-统计报告")
@RequestMapping("/admin/stats")
public class StatsController {
    @Resource
    StatsService statsService;
    @Resource
    NowUserGetter nowUserGetter;

    @Transactional
    @Operation(summary = "获取统计报告信息")
    @PostMapping("/getStatsReport")
    @ApiImplicitParam(dataType = "GetStatsReportParam", name = "getStatsReportParam", value = "统计报告", readOnly = true, required = true)
    @LogAnnotation(module = "ReportController", operation = "获取报告详情")
    public Result<StatsReportVo> getStatsReport(@RequestBody @Valid GetStatsReportParam getStatsReportParam) {
        NowUser nowUser = nowUserGetter.getNowUser();
        if (nowUser == null) {
            throw new BizException(ErrorCode.USER_LOGIN_ERROR_NO_LOGIN);
        }
        StatsReportVo result = statsService.getStatsReport(
                nowUser.getAccountId(),
                ParamUtil.parseIdList(getStatsReportParam.getCompanyIdList()),
                ParamUtil.parseIdList(getStatsReportParam.getDeptIdList()),
                getStatsReportParam.getStartDate(),
                getStatsReportParam.getEndDate()
        );
        return Result.success(result);
    }
}
